package com.zjlanyun.erp.approve;

import java.util.ArrayList;

import com.zjlanyun.erp.R;
import com.zjlanyun.erp.adapter.ApproveDetailCaigouAdapter;
import com.zjlanyun.erp.model.ApproveDetailCaigouModel;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

public class ApproveDetail extends Fragment {

	private View rootView;
	private ListView list;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		if (rootView == null) {
			rootView = LayoutInflater.from(getActivity()).inflate(
					R.layout.approve_detail, null);
		}
		ViewGroup parent = (ViewGroup) rootView.getParent();
		if (parent != null) {
			parent.removeView(rootView);
		}
		return rootView;
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		initView();
		getData();
	}
	
	// 初始化View
	private void initView(){
		list = (ListView) rootView.findViewById(R.id.list);
	}
	
	// 获取数据
	private void getData(){
		String[] titles = {"1.存货：友臣金丝肉松饼整箱2.5kg约70个 糕点休闲零食品 福建特产饼干","2.存货：5A级菲律宾进口芒果干 芒果108g*3包 芒果片 果干蜜饯","3.存货：台湾进口食品优之良品牛肉干肉铺进口零食 纯香牛肉条250g*2包"};
		String[] models = {"02001","02002","02003"};
		String[] units = {"包","包","包"};
		double[] quantity = {1500.00,30.00,20.00};
		double[] unitprice = {100.20,9.80,19.50};
		double[] money = {15000.00,294.00,390.00};
		
		ArrayList<ApproveDetailCaigouModel> mList = new ArrayList<ApproveDetailCaigouModel>();
		for(int i = 0; i < titles.length; i++){
			ApproveDetailCaigouModel model = new ApproveDetailCaigouModel();
			model.setTitle(titles[i]);
			model.setModel(models[i]);
			model.setUnit(units[i]);
			model.setQuantity(quantity[i]);
			model.setUnitprice(unitprice[i]);
			model.setMoney(money[i]);
			mList.add(model);
		}
		ApproveDetailCaigouAdapter mAdapter = new ApproveDetailCaigouAdapter(getActivity(), mList);
		list.setAdapter(mAdapter);
	}
}
